﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【在用绳检测】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto在用绳检测
    /// </summary>
    public abstract class AutoCheckWireropeMapping : BaseMapping<CheckWirerope, CheckWireropeModel, CheckWireropeFilterModel>
    {
        public AutoCheckWireropeMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override CheckWireropeModel Entity2Model(CheckWirerope entity)
        {
            CheckWireropeModel model = new CheckWireropeModel();

            model.CheckWireropeID = entity.CheckWireropeID;
            model.GroupInfoID = entity.GroupInfoID;
            model.Code = entity.Code;
            model.UsingWireropeID = entity.UsingWireropeID;
            model.Type = entity.Type;
            model.CheckUnit = entity.CheckUnit;
            model.CheckUserName = entity.CheckUserName;
            model.CheckDate = entity.CheckDate;
            model.NextCheckDate = entity.NextCheckDate;
            model.Status = entity.Status;
            model.IsSuggestChange = entity.IsSuggestChange;
            model.CreateUserID = entity.CreateUserID;
            model.CreateUserName = entity.CreateUserName;
            model.CreateDate = entity.CreateDate;
            model.SubmitUserID = entity.SubmitUserID;
            model.SubmitUserName = entity.SubmitUserName;
            model.SubmitDate = entity.SubmitDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override CheckWirerope Model2Entity(CheckWireropeModel model)
        {
            CheckWirerope entity = new CheckWirerope();

            entity.CheckWireropeID = model.CheckWireropeID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.Code = model.Code;
            entity.UsingWireropeID = model.UsingWireropeID;
            entity.Type = model.Type;
            entity.CheckUnit = model.CheckUnit;
            entity.CheckUserName = model.CheckUserName;
            entity.CheckDate = model.CheckDate;
            entity.NextCheckDate = model.NextCheckDate;
            entity.Status = model.Status;
            entity.IsSuggestChange = model.IsSuggestChange;
            entity.CreateUserID = model.CreateUserID;
            entity.CreateUserName = model.CreateUserName;
            entity.CreateDate = model.CreateDate;
            entity.SubmitUserID = model.SubmitUserID;
            entity.SubmitUserName = model.SubmitUserName;
            entity.SubmitDate = model.SubmitDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<CheckWirerope> FilterModel2Where(CheckWireropeFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._CheckWireropeID.HasValue)
            {
                where = where.And(x => x.CheckWireropeID == filterModel._CheckWireropeID.Value);
            }
            if (filterModel._CheckWireropeIDs.IsNotEmpty() && filterModel._CheckWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._CheckWireropeIDs.Contains(x.CheckWireropeID));
            }
            if (filterModel._NotCheckWireropeIDs.IsNotEmpty() && filterModel._NotCheckWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotCheckWireropeIDs.Contains(x.CheckWireropeID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //编码
            if (!string.IsNullOrEmpty(filterModel._Code))
            {
                where = where.And(x => x.Code.Contains(filterModel._Code));
            }
            if (!string.IsNullOrEmpty(filterModel._CodeEqual))
            {
                where = where.And(x => x.Code == filterModel._CodeEqual);
            }

            //在用绳
            if (filterModel._UsingWireropeID.HasValue)
            {
                where = where.And(x => x.UsingWireropeID == filterModel._UsingWireropeID.Value);
            }
            if (filterModel._UsingWireropeIDs.IsNotEmpty() && filterModel._UsingWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._UsingWireropeIDs.Contains(x.UsingWireropeID));
            }
            if (filterModel._NotUsingWireropeIDs.IsNotEmpty() && filterModel._NotUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUsingWireropeIDs.Contains(x.UsingWireropeID));
            }

            //检测类型
            if (filterModel._Type.HasValue)
            {
                where = where.And(x => x.Type == filterModel._Type.Value);
            }
            if (filterModel._Types.IsNotEmpty() && filterModel._Types.Count > 0)
            {
                where = where.And(x => filterModel._Types.Contains(x.Type));
            }
            if (filterModel._NotTypes.IsNotEmpty() && filterModel._NotTypes.Count > 0)
            {
                where = where.And(x => !filterModel._NotTypes.Contains(x.Type));
            }

            //检测人员
            if (!string.IsNullOrEmpty(filterModel._CheckUserName))
            {
                where = where.And(x => x.CheckUserName.Contains(filterModel._CheckUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._CheckUserNameEqual))
            {
                where = where.And(x => x.CheckUserName == filterModel._CheckUserNameEqual);
            }

            //检测日期
            if (filterModel._CheckDate.HasValue)
            {
                where = where.And(x => x.CheckDate == filterModel._CheckDate.Value);
            }
            if (filterModel._CheckDate_Begin.HasValue)
            {
                where = where.And(x => x.CheckDate >= filterModel._CheckDate_Begin.Value);
            }
            if (filterModel._CheckDate_End.HasValue)
            {
                where = where.And(x => x.CheckDate < filterModel._CheckDate_End.Value.AddDays(1));
            }

            //下次检测日期
            if (filterModel._NextCheckDate.HasValue)
            {
                where = where.And(x => x.NextCheckDate == filterModel._NextCheckDate.Value);
            }
            if (filterModel._NextCheckDate_Begin.HasValue)
            {
                where = where.And(x => x.NextCheckDate >= filterModel._NextCheckDate_Begin.Value);
            }
            if (filterModel._NextCheckDate_End.HasValue)
            {
                where = where.And(x => x.NextCheckDate < filterModel._NextCheckDate_End.Value.AddDays(1));
            }

            //状态
            if (filterModel._Status.HasValue)
            {
                where = where.And(x => x.Status == filterModel._Status.Value);
            }
            if (filterModel._Statuss.IsNotEmpty() && filterModel._Statuss.Count > 0)
            {
                where = where.And(x => filterModel._Statuss.Contains(x.Status));
            }
            if (filterModel._NotStatuss.IsNotEmpty() && filterModel._NotStatuss.Count > 0)
            {
                where = where.And(x => !filterModel._NotStatuss.Contains(x.Status));
            }

            //是否建议更换
            if (filterModel._IsSuggestChange.HasValue)
            {
                where = where.And(x => x.IsSuggestChange == filterModel._IsSuggestChange.Value);
            }
            if (filterModel._IsSuggestChanges.IsNotEmpty() && filterModel._IsSuggestChanges.Count > 0)
            {
                where = where.And(x => filterModel._IsSuggestChanges.Contains(x.IsSuggestChange));
            }
            
            //创建人姓名
            if (!string.IsNullOrEmpty(filterModel._CreateUserName))
            {
                where = where.And(x => x.CreateUserName.Contains(filterModel._CreateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._CreateUserNameEqual))
            {
                where = where.And(x => x.CreateUserName == filterModel._CreateUserNameEqual);
            }

            //创建时间
            if (filterModel._CreateDate.HasValue)
            {
                where = where.And(x => x.CreateDate == filterModel._CreateDate.Value);
            }
            if (filterModel._CreateDate_Begin.HasValue)
            {
                where = where.And(x => x.CreateDate >= filterModel._CreateDate_Begin.Value);
            }
            if (filterModel._CreateDate_End.HasValue)
            {
                where = where.And(x => x.CreateDate < filterModel._CreateDate_End.Value.AddDays(1));
            }

            //提交人姓名
            if (!string.IsNullOrEmpty(filterModel._SubmitUserName))
            {
                where = where.And(x => x.SubmitUserName.Contains(filterModel._SubmitUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._SubmitUserNameEqual))
            {
                where = where.And(x => x.SubmitUserName == filterModel._SubmitUserNameEqual);
            }

            //提交日期
            if (filterModel._SubmitDate.HasValue)
            {
                where = where.And(x => x.SubmitDate == filterModel._SubmitDate.Value);
            }
            if (filterModel._SubmitDate_Begin.HasValue)
            {
                where = where.And(x => x.SubmitDate >= filterModel._SubmitDate_Begin.Value);
            }
            if (filterModel._SubmitDate_End.HasValue)
            {
                where = where.And(x => x.SubmitDate < filterModel._SubmitDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

